function validateMail(email) {
		   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		   var address = email;
		   return reg.test(address);
		}
	function validateForm(action){
		var username = $('#USER_NAME').val();
		var password = $('#PASSWORD').val();
		var passconf = $('#passwordConfirmation').val();
		var first = $('#FIRST_NAME').val();
		var last = $('#LAST_NAME').val();
		var email = $('#EMAIL').val();
		var phone = $('#PHONE').val();
		//clear all error fields
		$('#USERERROR').text("");
		$('#PASSERROR').text("");
		$('#PASSCONFERROR').text("");
		$('#FIRSTERROR').text("");
		$('#LASTERROR').text("");
		$('#EMAILERROR').text("");
		$('#PHONEERROR').text("");
		var error = true;
		if (username.length==0) {
			$('#USERERROR').text("User name cannot be empty.");
			error = false;
		}
		if (username.length>255) {
			$('#USERERROR').text("User name cannot exceed 255 chars.");
			error = false;
		}
		if (email.length>255) {
			$('#EMAILERROR').text("Email cannot exceed 255 chars.");
			error = false;
		}
		if (email.length>0 && validateMail(email)==false){
			$('#EMAILERROR').text("Invalid email.");
			error = false;
		}
		if (action=="create" && password.length==0) {
			$('#PASSERROR').text("Password cannot be empty.");
			error = false;
		}
		if (password.length>255) {
			$('#PASSERROR').text("Password cannot exceed 255 chars.");
			error = false;
		}
		if (passconf!=password) {
			$('#PASSCONFERROR').text("Password confirmation failed.");
			error = false;
		}
		if (first.length>255) {
			$('#FIRSTERROR').text("First name cannot exceed 255 chars.");
			error = false;
		}
		if (last.length>255) {
			$('#LASTERROR').text("Last name cannot exceed 255 chars.");
			error = false;
		}
		if (phone.length>30) {
			$('#PHONEERROR').text("Phone number cannot exceed 30 digits.");
			error = false;
		}
		if(phone.length>0 && (/^\d+$/.test(phone)==false))
		{
			$('#PHONEERROR').text("Invalid phone number.");
			error = false;
		}
		return error;
	}